Creazione dataframe da singoli file con coordinate

VIDEO E ALGORITMO MIGLIORE SCELTO EMPIRICAMENTE

*pingpong :csrt;

*soccer :csrt;

*car_racing :csrt;

*mucche :csrt;

*aereoplani :mosse;

*tennis :mosse.

Metriche di confronto

IoU Precision e Recall

Intersection over Union

In object detection problems, IoU evaluates the overlap between ground-truth mask (gt) and the predicted mask (pd). It is calculated as the area of intersection between gt and pd divided by the area of the union of the two, that is,

Diagrammatically, IoU is defined as:

We can, therefore, redefine TP (correct detection) as a detection for which IoU≥ α and FP (invalid detection) with IoU< α. FN is a ground-truth missed by the model.

For example, at IoU threshold, α = 0.5 (or 50%), we can define TP, FP and FN as shown in the Fig 4 below.

Note: If we raise IoU threshold above 0.86, the first instance will be a FP and if we lower IoU threshold below 0.24, the second instance becomes TP.

###Precision and Recall

As started earlier TN are not used in object detection problems and therefore one as to avoid metrics based on this confusion matrix component such as True Negative Rate (TNR), False Positive Rate (FPR), Negative Predictive Value (NPC) and Receiver Operating Characteristic (ROC) curve. Instead, the evaluation of object detection models based on Precision (P) and Recall (R) which are defined as

Precision is the ability of a classifier to identify relevant objects only. It is the proportion of true positive detections.

Recall, on the other hand, measures the ability of the model to find all relevant cases (that is, all ground-truths) — the proportion of true positives detected among all ground-truths.

A good model is a model that can identify most ground-truth objects (high recall) while only finding the relevant objects (high precision) often. A perfect model is the one with FN=0 (recall=1) and FP=0 (precision=1). The former is usually the objective, the latter often unattainable.

The precision-recall (PR) curve is a plot of precision as a function of recall. It shows trade-off between the two metrics for varying confidence values for the model detections. If the FP is low, the precision is high but more object instances may be missed yielding high FN — low recall. Conversely, if one accepts more positives by lowering IoU threshold, α, the recall will increase but false positives may also increase, decreasing the precision score. For a good model, both precision and recall should remain high even if the confidence threshold varies.

Funzione di calcolo area overlap, intersezione e IOU

passo praticamente [ Ax, Ay, Bx, By ] per ogni rettangolo, dove A è il punto in alto a sinistra e B il punto in basso a destra

calcolo_area<-function(coord_1){
  return((coord_1[3]-coord_1[1])*(coord_1[4]-coord_1[2]))
}

intersezione_area <- function(coord_1, coord_2) {
  dx <-min(coord_1[3],coord_2[3])- max(coord_1[1],coord_2[1])
  dy<-min(coord_1[4],coord_2[4])- max(coord_1[2],coord_2[2])
  if (dx>=0 & dy>=0){
     return(dx*dy)}
    else{ return(0)}
}

unione_area <-function(coord_1,coord_2){
  return(calcolo_area(coord_1)+calcolo_area(coord_2)-intersezione_area(coord_1,coord_2))
}
IOU <- function(coord_1,coord_2){
  if(unione_area(coord_1,coord_2)!=0){
     return(intersezione_area(coord_1,coord_2)/unione_area(coord_1,coord_2))
  }else 
    return(0)}

Dataframe unico con numero del frame e coordinate dell’oggetto tracciato da ogni algortimo

Alcuni algoritmi hanno divere coordinate al prmo frame perché quello è il primo frame dove hanno iniziato a tracciare mentre le coordinate dell’oggetto nel frame 0 passate all’algoritmo sono uguali per tutti

Aggiungo la colonna con i valori di IOU calcolati tra l’algoritmo empiricamente migliore(scelto come valore di ground truth)

PRECISION & RECALL

precision = tp/tp+fp recall = tp/tp+fn

false positive

If IoU < 0.5. This means that we are drawing a bounding box around an object but classifying it as another object. Suppose that we are detecting dogs and cats in an image. When the algorithm detects a dog but misclassifies it as a cat, then it is the case false positive.

true positive

If IoU >= 0.5. This means that there is an object and we have detected it.

false negative

This is the case when the algorithm does not detect anything when it should be detecting. For example, there is a dog in the image but the algorithm does not draw any bounding box around it.

Plot posizione oggetto su ogni frame per confronto empirico

(l’asse y è invertito rispetto al video poiché opencv prende come punto (0,0) il punto in alto a sinistra)

Quando il tracker si sposta nel punto (0,0) il tracker non ha trovato l’ogetto in quel frame